import ImportModal from '#/components/ImportModal/ImportModal.vue'
import ImportModalRecord from '#/components/ImportModalRecord/ImportModalRecord.vue'
import { useVbenModal } from '@vben/common-ui'
import type { AnyFn } from '@vueuse/core'
/**
 * 导入弹窗
 */
export function useImportModal(opts?: {
    accept?: string[]
    api?: AnyFn
    maxNumber?: number
    mmaxSize?: number
    onClose?: (...args: any[]) => any
    templateName?: string
    templateUrl?: string
    title?: string
}) {
    const [Modal, ModalApi] = useVbenModal({
        connectedComponent: ImportModal,
        onClosed: () => {
            opts?.onClose?.()
        }
    })

    function openModal(data?: typeof opts) {
        // 设置模态框数据
        ModalApi.setData({
            ...opts,
            ...data
        })
        ModalApi.open()
    }

    return {
        ImportModal: Modal,
        ImportModalApi: ModalApi,
        openImportModal: openModal
    }
}

/**
 * 导入记录弹窗
 */
export function useImportModalRecord(opts?: { api?: AnyFn; title?: string }) {
    const [Modal, ModalApi] = useVbenModal({
        connectedComponent: ImportModalRecord
    })

    function openModal(data?: typeof opts) {
        // 设置模态框数据
        ModalApi.setData({
            ...opts,
            ...data
        })
        ModalApi.open()
    }

    return {
        ImportModalRecord: Modal,
        ImportModalRecordApi: ModalApi,
        openImportModalRecord: openModal
    }
}
